package br.inf.ufrgs.usixml4cdc.logicconector.java;

import br.inf.ufrgs.usixml4cdc.exceptions.MethodCallException;
import br.inf.ufrgs.usixml4cdc.exceptions.MethodConfigurationException;
import br.inf.ufrgs.usixml4cdc.logicconector.LogicConector;

public class JavaLogicConector implements LogicConector {

	private MethodDefinition currentMethod = null;
	
	
	public void executeMethod() throws MethodCallException {
		this.getMethodDefinition().callMethod();
	}

	public double getMethodReturnDouble() throws MethodConfigurationException {
		return this.getMethodDefinition().getDoubleReturnValue().doubleValue();
	}

	public int getMethodReturnInteger() throws MethodConfigurationException {
		return this.getMethodDefinition().getIntegerReturnValue().intValue();
	}

	public String getMethodReturnString() throws MethodConfigurationException {
		return this.getMethodDefinition().getStringReturnValue();
	}

	public void prepareMethodDoubleParameter(double parameter, int position) {
		this.getMethodDefinition().addParameter(new Double(parameter), position);
	}

	public void prepareMethodIntegerParameter(int parameter, int position) {
		this.getMethodDefinition().addParameter(new Integer(parameter), position);
	}

	public void prepareMethodName(String methodName) {
		this.getMethodDefinition().setMethodName(methodName);
	}
	
	public void prepareMethodClass(String methodClass) {
		this.getMethodDefinition().setClassName(methodClass);
	}

	public void prepareMethodStringParameter(String parameter, int position) {
		this.getMethodDefinition().addParameter(parameter, position);
	}

	public void prepareMethodDoubleReturnParameter() throws MethodConfigurationException {
		this.getMethodDefinition().setMethodReturnType(0);//DOUBLE
		
	}

	public void prepareMethodIntegerReturnParameter() throws MethodConfigurationException {
		this.getMethodDefinition().setMethodReturnType(1);//INTEGER
		
	}

	public void prepareMethodStringReturnParameter() throws MethodConfigurationException {
		this.getMethodDefinition().setMethodReturnType(2);//STRING
	}
	
	private MethodDefinition getMethodDefinition(){
		if (this.currentMethod == null){
			this.currentMethod = new MethodDefinition();
		}
		
		return this.currentMethod;
	}

	public void initializeMethod() {
		this.currentMethod = null;
	}

}
